package interfaz;


import datos.Diente;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Label;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.GeneralPath;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JComboBox;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import negocio.ui.uiClinica;
import sun.java2d.loops.DrawLine;
import sun.java2d.loops.FillRect;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author Christopher
 */
public class Dibujo extends javax.swing.JFrame implements MouseListener, ItemListener, ListSelectionListener, Serializable {
    uiClinica ui = uiClinica.getInstance();
    
    Diente d;
    
    private boolean dibujaLinea = false;
    
    int x4;
    int y4;
    int cont5=0;
    int x5;
    int y5;
   
    public Dibujo() {
        super();
        initComponents();
        addMouseListener(this);
        jListTipos.addListSelectionListener(this);
        d = new Diente();
        inicializaEnBlanco();
        


    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        buttonGroup5 = new javax.swing.ButtonGroup();
        buttonGroup6 = new javax.swing.ButtonGroup();
        buttonGroup7 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jRadioButton3 = new javax.swing.JRadioButton();
        jLabel5 = new javax.swing.JLabel();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jRadioButton12 = new javax.swing.JRadioButton();
        jRadioButton14 = new javax.swing.JRadioButton();
        jRadioButton13 = new javax.swing.JRadioButton();
        jRadioButton15 = new javax.swing.JRadioButton();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jRadioButton16 = new javax.swing.JRadioButton();
        jRadioButton17 = new javax.swing.JRadioButton();
        jRadioButton18 = new javax.swing.JRadioButton();
        jRadioButton19 = new javax.swing.JRadioButton();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jButtonGuardarOdontograma = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListTipos = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jButtonBorrar = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Odontograma");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMinimumSize(new java.awt.Dimension(1000, 700));
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel2.setText("Examen Radiografico");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 0, -1, -1));

        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jRadioButton3.setText("jRadioButton3");
        jPanel3.add(jRadioButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(62, 18, -1, -1));

        jLabel5.setText("jLabel5");
        jPanel3.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 22, -1, -1));

        jRadioButton4.setText("jRadioButton3");
        jPanel3.add(jRadioButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(62, 41, -1, -1));

        jRadioButton5.setText("jRadioButton3");
        jPanel3.add(jRadioButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(62, 67, -1, -1));

        jRadioButton6.setText("jRadioButton3");
        jPanel3.add(jRadioButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(62, 117, -1, -1));

        jRadioButton7.setText("jRadioButton3");
        jPanel3.add(jRadioButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(62, 94, -1, -1));

        jLabel6.setText("jLabel5");
        jPanel3.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 45, -1, -1));

        jLabel7.setText("jLabel5");
        jPanel3.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 71, -1, -1));

        jLabel8.setText("jLabel5");
        jPanel3.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 98, -1, -1));

        jLabel9.setText("jLabel5");
        jPanel3.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 121, -1, -1));

        jPanel1.add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(399, 38, 213, -1));

        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane2.setViewportView(jTextArea1);

        jPanel4.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 31, 300, -1));

        jLabel4.setText("Observaciones:");
        jPanel4.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        jPanel1.add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(618, 107, -1, 131));

        jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jRadioButton1.setText("jRadioButton1");
        jPanel5.add(jRadioButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 7, -1, -1));

        jRadioButton2.setText("jRadioButton2");
        jPanel5.add(jRadioButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 33, -1, -1));

        jLabel3.setText("Presencia de patologia:");
        jPanel5.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        jPanel1.add(jPanel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(618, 38, -1, -1));

        jPanel6.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel10.setText("Examen Clinico");
        jPanel6.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 0, -1, -1));

        jPanel7.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel17.setText("SI");
        jPanel7.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(73, 11, -1, -1));

        jLabel18.setText("NO");
        jPanel7.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(101, 11, -1, -1));

        jRadioButton12.setText("j");
        jPanel7.add(jRadioButton12, new org.netbeans.lib.awtextra.AbsoluteConstraints(66, 32, -1, -1));

        jRadioButton14.setText("j");
        jPanel7.add(jRadioButton14, new org.netbeans.lib.awtextra.AbsoluteConstraints(97, 32, -1, -1));

        jRadioButton13.setText("j");
        jPanel7.add(jRadioButton13, new org.netbeans.lib.awtextra.AbsoluteConstraints(66, 57, -1, -1));

        jRadioButton15.setText("j");
        jPanel7.add(jRadioButton15, new org.netbeans.lib.awtextra.AbsoluteConstraints(97, 57, -1, -1));

        jLabel11.setText("jLabel11");
        jPanel7.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 36, -1, -1));

        jLabel12.setText("jLabel11");
        jPanel7.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 61, -1, -1));

        jPanel6.add(jPanel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 11, -1, 79));

        jPanel8.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel19.setText("SI");
        jPanel8.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(53, 18, -1, -1));

        jLabel20.setText("NO");
        jPanel8.add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(81, 18, -1, -1));

        jRadioButton16.setText("j");
        jPanel8.add(jRadioButton16, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 39, -1, -1));

        jRadioButton17.setText("j");
        jPanel8.add(jRadioButton17, new org.netbeans.lib.awtextra.AbsoluteConstraints(77, 39, -1, -1));

        jRadioButton18.setText("j");
        jPanel8.add(jRadioButton18, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 64, -1, -1));

        jRadioButton19.setText("j");
        jPanel8.add(jRadioButton19, new org.netbeans.lib.awtextra.AbsoluteConstraints(77, 64, -1, -1));

        jLabel21.setText("jLabel11");
        jPanel8.add(jLabel21, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 43, -1, -1));

        jLabel22.setText("jLabel11");
        jPanel8.add(jLabel22, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 68, -1, -1));

        jPanel6.add(jPanel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(41, 101, -1, -1));

        jPanel9.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel13.setText("Especificar:");
        jPanel9.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane3.setViewportView(jTextArea2);

        jPanel9.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 31, 186, -1));

        jPanel6.add(jPanel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 58, -1, 137));

        jButtonGuardarOdontograma.setText("Guardar Plantilla");
        jButtonGuardarOdontograma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarOdontogramaActionPerformed(evt);
            }
        });
        jPanel6.add(jButtonGuardarOdontograma, new org.netbeans.lib.awtextra.AbsoluteConstraints(131, 234, -1, -1));

        jPanel1.add(jPanel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 359, -1));

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel1.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(381, 11, 12, 224));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 11, -1, -1));

        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jListTipos.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Carie", "Aparato Ortodontico Fijo", "Aparato Ortodontico Removible", "Corona Definitiva", "Corona Temporal", "Desgaste Oclusal/Incisal", "Diastema", "Diente Ausente", "Diente Discromico", "Diente Ectopico", "Diente en clavija", "Diente Extruido", "Diente Intruido", "Edentulo Total", "Fractura", "Geminacion/Fusion", "Giroversion", "Impactacion", "Implante", " " };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jListTipos.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListTiposValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jListTipos);

        jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 31, 209, 166));

        jLabel1.setText("Disposiciones Especificas");
        jPanel2.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(47, 11, -1, -1));

        jButtonBorrar.setText("Borrar");
        jButtonBorrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBorrarActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonBorrar, new org.netbeans.lib.awtextra.AbsoluteConstraints(71, 215, -1, -1));

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 300, -1, -1));

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jListTiposValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListTiposValueChanged

    }//GEN-LAST:event_jListTiposValueChanged

    private void jButtonBorrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBorrarActionPerformed
       
    }//GEN-LAST:event_jButtonBorrarActionPerformed

    private void jButtonGuardarOdontogramaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarOdontogramaActionPerformed


    }//GEN-LAST:event_jButtonGuardarOdontogramaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Dibujo().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.ButtonGroup buttonGroup5;
    private javax.swing.ButtonGroup buttonGroup6;
    private javax.swing.ButtonGroup buttonGroup7;
    private javax.swing.JButton jButtonBorrar;
    private javax.swing.JButton jButtonGuardarOdontograma;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jListTipos;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton12;
    private javax.swing.JRadioButton jRadioButton13;
    private javax.swing.JRadioButton jRadioButton14;
    private javax.swing.JRadioButton jRadioButton15;
    private javax.swing.JRadioButton jRadioButton16;
    private javax.swing.JRadioButton jRadioButton17;
    private javax.swing.JRadioButton jRadioButton18;
    private javax.swing.JRadioButton jRadioButton19;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    // End of variables declaration//GEN-END:variables

    
    public void inicializaEnBlanco()
    {
        for(int cont=0;cont<2;cont++)
        {
            for(int cont2=0;cont2<16;cont2++)
            {
                for(int cont3=0;cont3<5;cont3++)
                {
                    d.getColorDienteP()[cont][cont2][cont3] = Color.WHITE;
                }
            }
        }
        
        for(int cont=0;cont<2;cont++)
        {
            for(int cont2=0;cont2<10;cont2++)
            {
                for(int cont3=0;cont3<5;cont3++)
                {
                    d.getColorDienteT()[cont][cont2][cont3] = Color.WHITE;
                }
            }
        }
    }
    
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2 = (Graphics2D) g;

        
        //creaD(p1p1,posicionX,posicionY,cp1p1,g2);
        
        d.crearDiente(g2);
        
        g2.setColor(Color.BLUE);
        g2.fillRect(x4, y4, x5-x4, 5);
        
    }


    public void mouseClicked(MouseEvent e) {
        if(dibujaLinea){
            cont5++;
            
            if(cont5 == 1){
            
            x4 = e.getX();
            y4 = e.getY();
            }
            
            if(cont5 == 2){
            
            x5 = e.getX();
            y5 = e.getY();
            }
            
        }
        if(cont5>1){repaint();}
        System.out.println(x4 + "\n" + y4);
        
        
        for (int cont = 0; cont < 2; cont++) {

            for (int cont2 = 0; cont2 < 16; cont2++) {

                for (int cont3 = 0; cont3 < 5; cont3++) {
                    
                    if(d.getParteDiente()[cont][cont2][cont3].contains(e.getX(),e.getY()))
                    {
                        d.getColorDienteP()[cont][cont2][cont3] = d.getColorsito();
                    }
                }
            }
        }
        for (int cont = 0; cont < 2; cont++) {

            for (int cont2 = 0; cont2 < 10; cont2++) {

                for (int cont3 = 0; cont3 < 5; cont3++) {
                    
                    if(d.getParteDienteT()[cont][cont2][cont3].contains(e.getX(),e.getY()))
                    {
                        d.getColorDienteT()[cont][cont2][cont3] = d.getColorsito();
                    }
                }
            }
        }
    repaint();    
    }


    public void mousePressed(MouseEvent e) {

    }


    public void mouseReleased(MouseEvent e) {
   
    }

   
    public void mouseEntered(MouseEvent e) {
  
    }

  
    public void mouseExited(MouseEvent e) {
  
    }

    public void itemStateChanged(ItemEvent e) {

    }

    public void valueChanged(ListSelectionEvent e) {

        if (jListTipos.getSelectedValue().toString().equals("Carie")) {
            d.setColorsito(Color.red);
            //dibujaLinea = true;
            System.out.println("Me pica");
        }




        if (jListTipos.getSelectedValue().toString().equals("Diente Intruido")) {
            dibujaLinea = true;
            System.out.println("Me pica");
        }

    }
}
